﻿<?php
/*
sendsms.php?action=add&username=13713178073&password=f2pEbjPs&nickname=4S系统&sendto=13713393257
sendsms.php?username=13713393257&password=ice820518&sendto=13713393257
*/

require_once './inc/config.php';
require './lib/MyFetion.php';
require './lib/Logger.class.php';

// 获取请求参数
$username=$_GET["username"];
$password=$_GET["password"];
$sendto=isset($_GET["sendto"])? $_GET["sendto"] : $username;
$action = isset($_GET["action"])? $_GET["action"] : 'send';

// 登陆获取Session 手机号、飞信密码
$fetion = new MyFetion($username, $password);
// 是否自动退出飞信
$fetion->_userlogout=isset($_GET["logout"])? $_GET["logout"] : true;

switch ($action) {
	case 'add' :
		$nickname=substr(isset($_GET["nickname"])? $_GET["nickname"] : 'SMS系统', 0, 5);
		$nickname=mb_convert_encoding($nickname, "UTF-8", "gb2312");
		$ret=$fetion->addFriend($sendto, $nickname);
		break;
	case 'del' :
		$ret=$fetion->delFriend($sendto);
		break;
	case 'msg':
		$ret=$fetion->getMsg();
		break;
	case 'test':
		$ret=$fetion->test();
		break;
	default:
		//发送短信
		$message=isset($_GET["message"])? $_GET["message"] : '';
		$message=mb_convert_encoding($_GET["message"], "UTF-8", "gb2312");
		$ret=$fetion->send($sendto, $message);	// 接收人手机号、飞信内容
		break;
}

//输出返回信息
Logger::debug($ret);
print($ret);

?>
